// 获取路由参数

export const getRouteParams = (props = {}) => {
    const {match = {}} = props;
    const {params = {}} = match;
    return params;
};

// 获取地址参数
export const getUrlParams = (url = '') => {
    let params = {};

    const urlParams = url.slice(url.indexOf('?') + 1).split('&');
    urlParams.forEach((item) => {
        const param = item.split('=');
        params[param[0]] = param[1];
    });

    return params;
};

export const _scanQRCode = (callback) => {
    try {
        const isExist = window.em && window.em.checkJsApi('scanQRCode');
        if (!isExist) return;
        window.em.scanQRCode({
            needResult: 1,
            scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码，默认二者都有
            success: function (res) {
                /*
                * {"errMsg":"scanQRCode:ok","clientType":"iPhone","resultStr":"wear000100020100001","errCode":0}
                * */
                callback(res.resultStr);
            },
        });
    } catch (e) {
    }
};
